<?php
Class User extends CI_Model
{
 function login()
 {
   $username = trim($this->input->post('inputUsername'));
   $username = strtolower($username);
   $password = $this->input->post('inputPassword');
   $this -> db -> select('cust_id, username, password');
   $this -> db -> from('customer');
   $this -> db -> where('username', $username);
   $this -> db -> where('password', MD5($password));
   $this -> db -> limit(1);

   $query = $this -> db -> get();

   if($query -> num_rows() == 1)
   {
       return $query->result();
   }
   else
   {
     return FALSE;
   }
 }
 function register()
 {
   //mix                
   $birthdate = $this->input->post('birthdate');
   $birthdate = date('Y-m-d', strtotime($birthdate)); 
   $data = array(
       'username' => $this->input->post('Username'),
       'password' => MD5($this->input->post('Password')) ,
       'firstname' => $this->input->post('Firstname'),
       'lastname' => $this->input->post('Lastname'),
       'birthdate' => $birthdate,
       'sex' => $this->input->post('sex'),
       'address' => $this->input->post('address'),
       'email' => $this->input->post('Email'),
       'tel' => $this->input->post('tel'),
       'status' => 0,
       'iden' => $this->input->post('iden'),
       'code' => $this->input->post('code'),
       'province' => $this->input->post('prov')
    );
   $this->db->insert('customer', $data);
   
   return true;
 }
 function check_username_availablity()
{
        $username = trim($this->input->post('Username'));
	$username = strtolower($username);	
	$this -> db -> select('username');
        $this -> db -> from('customer');
        $this -> db -> where('username', $username);
        $this -> db -> limit(1);
        $query = $this -> db -> get();

        if($query -> num_rows() == 1)
        {
              return $query->result();
        }
        else
        {
          return false;
        }
}
}
?>